<template>
	<view class="u-page">
		<zb-dropdown-menu style="width: 100%" active-color="#00aaff">
			<zb-dropdown-item name="first" :options="option" v-model="value1" @change="change1"></zb-dropdown-item>
			<zb-dropdown-item name="two" :options="option2" v-model="value2" @change="change2"></zb-dropdown-item>
		</zb-dropdown-menu>
	   <div v-if="list1<1">
		   <u-empty
		           mode="list"
		           icon="http://cdn.uviewui.com/uview/empty/list.png"	
		   >
		   </u-empty>
	   </div>
		<div v-else>
			<u-list @scrolltolower="scrolltolower" style="zoom: 110%;">
				<u-list-item v-for="(item, index) in indexList" :key="index">
				<!-- 	<view class="uni-card__header-extra" @click="onClick('extra')">
						<text class="uni-card__header-extra-text">{{ extra }}</text>
					</view> -->
						<uni-card :title="item.product_name" sub-title="项目名" @click="more(index,item.id,$event)" >
							<text>驾驶员姓名：</text><text>{{item.name}}</text>
							<br>
							<text>培训类型：</text><text>{{item.product_category_name}}</text>
							<br>
							<text>培训组织：</text><text>{{item.product_org_name}}</text>
							<br>
							<text>所属车队：</text><text>{{item.org_name}}</text>
							<br>
							<div v-if="item.status==0">
							<text>任务情况：</text><text style="color: gray;">未开始</text>
							</div>
							<div v-else-if="item.status==1">
							<text>任务情况：</text><text style="color: green;">已开始</text>
							</div>
							<div v-else-if="item.status==2">
							<text>任务情况：</text><text style="color: orange;">已结束</text>
							</div>
							<br>
							<text>开始时间：</text><text>{{$u.timeFormat(item.product_start_time, 'yyyy年mm月dd日')}}</text>
							<br>
							<text>截止时间：</text><text>{{$u.timeFormat(item.product_over_time, 'yyyy年mm月dd日')}}</text>
							<br>
						
							<div v-if="item.condition==0">
								
								<text>状态：</text><view style="width: 3rem;display: inline-block;"><u-tag text="未完成" plain size="mini"></u-tag></view>
								
								 <!-- <text>审核状态：</text><u-tag text="已完成待审核" type="warning" plain size="mini" style="width: 5.3rem;display: inline-block;"></u-tag> -->
							</div>
							<div v-else-if="item.condition==1">
			
								<text>状态：</text><view class="" style="width: 5.3rem;display: inline-block;"><u-tag text="已完成待审核" plain size="mini"></u-tag></view>
							</div>
							<div v-else-if="item.condition==2">
								<text>状态：</text><view class="" style="width: 4rem;display: inline-block;"><u-tag text="审核通过" type="success" plain size="mini"></u-tag></view>
							</div>
							<div v-else-if="item.condition==3">
								<view class="" style="width: 5.5em;display: inline-block;"><u-tag text="审核不通过" type="warning" plain size="mini"></u-tag></view>
								<text>状态：</text>
							</div>
						</uni-card>
				</u-list-item>
			</u-list>
		</div>
		
	<!-- 	<u-tabbar
			:value="value6"
			@change="name => value6 = name"
			:fixed="true"
			:placeholder="true"
			:safeAreaInsetBottom="true"
		>
			<u-tabbar-item text="培训列表" icon="play-right" ></u-tabbar-item>
			<u-tabbar-item text="个人中心" icon="account" ></u-tabbar-item>
		</u-tabbar> -->
	</view>
	
</template>

<script>
import indexList from '../../uni_modules/uview-ui/libs/config/props/indexList';
import { onLoad } from '../../uni_modules/uview-ui/libs/mixin/mixin';
	export default {
		data() {
			return {
				indexList: [],
				option: [{
						text: '全部',
						value: ''
					},
					{
						text: '未完成',
						value: 0
					},
					{
						text: '已完成待审核',
						value: 1
					},
					{
						text: '审核通过',
						value: 2
					},
					{
						text: '审核不通过',
						value: 3
					},
				],
				option2: [{
						text: '日期降序',
						value: "ud.product_create_time desc"
					},
					{
						text: '日期升序',
						value: "ud.product_create_time asc"
					},
				],
				value1: '',
				value2: '',
				value6:0,
				page:0,
				list1:1,
				userid:"",
				//             list: ['未上传', '待审核', '已结束'],
				// curNow: 0
			}
		},
		// created(){
		// 	alert(123);
		// },
		onLoad(option) {
			
			// this.page--;
			this.checklogin();
			// this.userid = option.userid;
			this.loadmore();
			
		},
		onShow: function() {
		            uni.$once('query' ,(query)=>{
						//console.log();
						this.indexList[query.index].condition=1;
		            });
		        },
		// onShow(){
		// 	this.loadmore();
		// 	},
		mounted() {
			this.value1 = this.option[0]['value'];
			this.value2 = this.option2[0]['value'];
			// alert(this.list1);
		},
		methods: {
			checklogin(){
				var userid = uni.getStorageSync("userid");
				this.userid = userid;
				console.log(userid);
				console.log(this.userid);
				if (typeof(userid)=="undefined" || userid=='' || userid==null)
				{
				  uni.navigateTo({
				  	url: "/pages/index/index"
				  });
				}
			},
			more(index,id,e){
				// console.log(index);
				 // console.log(this.indexList[index].condition);
				 //  this.indexList[index].condition=2;
				uni.navigateTo({
					
					url: "/pages/dtest/index?id="+id+"&index="+index,
				});
				
			},
			change1(item) {
				// alert(this.value1);
				console.log(item);
				this.search();
				// alert(123);
			},
			change2(item) {
				// alert(this.indexList.length);
				console.log(item);
				if(this.indexList.length>0){
		
				   this.search()	
				}
				
			},
			scrolltolower() {
				this.loadmore()
			},
			search(){
				
				this.page=0;
				if(this.indexList.length>0){
					this.indexList=[]
				}
			//this.indexList=[];
				this.loadmore()
			},
			loadmore() {
				if(this.value2==""){
					this.value2="ud.product_create_time desc";
				}
				// alert(this.value2);
				this.page++;
				// this.indexList=[];
				var page = this.page;
				var limit = 5;
				// if(page>1){
				// 	return;
				// }
				uni.$u.http.get('https://ss.dzbx.zsbike.com.cn:8199/api.v1/List?limit='+limit+'&page='+page+"&userid="+this.userid+"&condition="+this.value1+"&order="+this.value2,).then(res => {
					if(res.data.status==1){
						 	let arr = res.data.data;
						 	for(let item of arr){
								this.indexList.push(item);
						 	}
						 	this.list1=1;
				
						 }else{
							 if(this.indexList.length<1){
								 this.list1=0;
							 }else{
								 this.page--;
								 this.list1=1;
							 }
							 //alert(arr.length);
						 	
						 }
					
				}).catch(err => {
				
				})
			
				// for (let i = 0; i < 30; i++) {
				// 	this.indexList.push()
				// }
			},
			listdetail(index){
				alert(index);
			},
		}
	}
</script>